using System.Text.Json;

#if MY_TEST
using Xunit;
public class T02 {
    // readonly I01Backable? i1 = new I01Backable.Mock();
    readonly I01Backable i1 = new GrpcLiaison("http://192.168.1.181:50052");

    [Fact]
    public async Task TTestF0() {
        string p = "/home/me/repo/work/n3c/hi-sow.docx";
        string p1 = "/home/me/repo/work/n3c/hi-cli.docx";
        var bs = await File.ReadAllBytesAsync(p);
        var bs1 = await File.ReadAllBytesAsync(p1);

        C00_InitialInput i = new C00_InitialInput {
            projectId = "mock-project-id",
            projectName = "Mock Project",
            sowDocx = bs, cliDocx = bs1
        };
        // call
        C01_TextSoW o = await i1.F0_ParseInitialInput(i);
        // mock check
        Assert.Equal(1,1);
    }

static C01_TextSoW MockTextSoW() {
    string ps = "Processed SOW content";
    string pc = "Processed CLI content";
    string pnt = "Processed notes";
    string cq = "Clarification questions";
    string ua = "Example user question";
    C01_TextSoW t = new C01_TextSoW {
        pSow = ps,
        pCli = pc,
        pNotes = pnt,
        cQ = cq,
        uA = ua,
    };
    return t;
}

[Fact]
public async Task TestF1() {
        // call
        IList<C03_TestCase> o = await i1.F1_TextSoW2Testcases(MockTextSoW());
        // mock check
        Assert.NotNull(o);
        Assert.Equal(5, o.Count); // Mock returns 5 test cases
    }

    [Fact]
    public async Task TestF2() {
        // call
        C02_NetworkSetup o = await i1.F2_GetCommonNetworkSetup(MockTextSoW());
        // mock check
        Assert.NotNull(o);
        Assert.NotNull(o.id);
        Assert.NotNull(o.topox);
        Assert.NotNull(o.conftestPy);
    }

    [Fact]
    public async Task TestF3() {
        string tn = "Test Script Generation";
        string pid = "script-project-id";
        var st = new List<C03_TestCase.E> {
            new C03_TestCase.E("Connect to device", "Connection successful"),
            new C03_TestCase.E("Run command", "Command executed")
        };

        C03_TestCase tc = new C03_TestCase {name = tn, steps = st};

        string nid = "network-id";
        string tx = "<topology>test</topology>";
        string cf = "# conftest.py content";

        C02_NetworkSetup ns = new C02_NetworkSetup {
            id = nid,
            topox = tx,
            conftestPy = cf
        };

        // call
        C04_TestScript o = await i1.F3_GenerateScript(tc, ns);
        // mock check
        Assert.NotNull(o);
        Assert.NotNull(o.pyscript);
    }

    [Fact]
    public async Task TestF4() {
        string py = "import pytest\ndef test_example():\n    assert True";
        
        C04_TestScript ts = new C04_TestScript {
            pyscript = py
        };

        string nid = "run-network-id";
        string tx = "<topology>run test</topology>";
        string cf = "# run conftest.py";

        C02_NetworkSetup ns = new C02_NetworkSetup {
            id = nid,
            topox = tx,
            conftestPy = cf
        };

        // call
        C05_TestResult o = await i1.F4_RunAndGetLog(ts, ns);
        // mock check
        Assert.NotNull(o);
        Assert.NotNull(o.l);
    }
}

    #endif
